layui.use(['form','laytpl'], function () {
    let form = layui.form,
        layer = layui.layer,
        laytpl = layui.laytpl,
        formSelects = layui.formSelects;
    $ = layui.$;

    //角色下拉选项
    getAjax(false, "/api/role/search/list", '',function (res) {
        if(res.code == 0){
            if(res.data != null){
                let htmlStr = '<option value = "">请选择</option>'
                for(let row in res.data){
                    htmlStr += '<option value = "' + res.data[row].id + '">'+res.data[row].roleName+'</option>'
                }
                $("#role-view").html(htmlStr);
                formSelects.render('role-select');
            }
        }else {
            let index = layer.alert(res.msg, {title: '提示', closeBtn: 0}, function () {
                layer.close(index);
                let iframeIndex = parent.layer.getFrameIndex(window.name);
                parent.layer.close(iframeIndex);
            });
            return false;
        }
    });


    //监听提交
    form.on('submit(saveBtn)', function (data) {
        postAjax("/api/user/edit", data.field, function (res) {
            if(res.code == 0){
                let index = layer.alert("保存成功", { title: '提示', closeBtn: 0 }, function () {
                    layer.close(index);
                    let iframeIndex = parent.layer.getFrameIndex(window.name);
                    console.log(window.parent.reload())
                    parent.layer.close(iframeIndex);
                });
            }else {
                layer.alert(res.msg, { title: '提示' });
            }
        })
        return false;
    });
});